package com.bookstore.model.dao;

import java.util.List;
import org.hibernate.Session;

import com.bookstore.model.entity.Book;
import com.bookstore.model.util.HibernateUtil;

public class BookDAO {	
	
	public List<Book> listAll(){
		Session session = HibernateUtil.getSession();
		session.beginTransaction();
		@SuppressWarnings("unchecked")
		List<Book> bookList = session.createQuery("from Book").list();
		session.getTransaction().commit();
		return bookList;
	}
	
	public void addBook(Book newBook){
		Session session = HibernateUtil.getSession();
		session.beginTransaction();
		session.saveOrUpdate(newBook);
		session.getTransaction().commit();
	}
	

}
